#include <btBulletCollisionCommon.h>
#include "SDLPlayerController.h"

#include <iostream>
using namespace std;

SDLPlayerController::SDLPlayerController(Object *player) {
	moveForward = SDLK_w;
	moveBackward = SDLK_s;
	strafeLeft = SDLK_a;
	strafeRight = SDLK_d;
	motionController = new PlayerMotionController(player);
}

void SDLPlayerController::handleEvent(SDL_Event event, float dts) {
	if (event.type == SDL_KEYDOWN) {
		if (event.key.keysym.sym == moveForward) {
			motionController->setMoveForward(true);
		}
		if (event.key.keysym.sym == moveBackward) {
			motionController->setMoveBackward(true);
		}
		if (event.key.keysym.sym == strafeLeft) {
			motionController->setStrafeLeft(true);
		}
		if (event.key.keysym.sym == strafeRight) {
			motionController->setStrafeRight(true);
		}
	}
	else if (event.type == SDL_KEYUP){
		if (event.key.keysym.sym == moveForward) {
			motionController->setMoveForward(false);
		}
		if (event.key.keysym.sym == moveBackward) {
			motionController->setMoveBackward(false);
		}
		if (event.key.keysym.sym == strafeLeft) {
			motionController->setStrafeLeft(false);
		}
		if (event.key.keysym.sym == strafeRight) {
			motionController->setStrafeRight(false);
		}
	}
	else if (event.type == SDL_MOUSEMOTION) {
		motionController->setPitch(event.motion.yrel);
		motionController->setYaw((float)-event.motion.xrel);
	}
}

SDLPlayerController::~SDLPlayerController() {
	delete motionController;
}
